package org.teststack.Api.Sl.MCcc;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import org.apache.commons.codec.net.URLCodec;
import org.teststack.Api.RestClient;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static org.teststack.Api.CookieManager.cookies;


public class ZhApi {
    public static void main(String[] args) throws UnsupportedEncodingException {
        zhApi();
        zhApi1();

    }




    public static int zhApi() throws UnsupportedEncodingException {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");



        String zwzh = "非脚后跟";
        URLCodec urlCodec = new URLCodec();


        String encodedParam = URLEncoder.encode(zwzh, "GBK");

        String formData = "zwzh=" + encodedParam;

            // 注意：这里我们仍然将参数放在查询字符串中，尽管这是一个POST请求
            // 如果API设计为接受查询参数，则这是可以的；否则，应考虑将参数放在请求体中
            Response response = RestAssured.given()
                    .body(formData)
                    .cookies(cookies)
                    .baseUri("http://10.1.10.141:9031")
                    .post("/mcdj.do?method=checkTyc&csrftoken="); // 假设这里有一个有效的CSRF Token或它是不必要的

            int statusCode = response.getStatusCode();
            String body = response.getBody().asString();

            System.out.println("Status Code: " + statusCode);
            System.out.println("Response Body: " + body);

            return statusCode;


    }
    public static int zhApi1() throws UnsupportedEncodingException {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");



        String getValue = "非脚后跟";
        URLCodec urlCodec = new URLCodec();


        String encodedParam = URLEncoder.encode(getValue, "GBK");

        String formData = "&"+ "getValue=" + encodedParam;
        System.out.println(formData);
        // 注意：这里我们仍然将参数放在查询字符串中，尽管这是一个POST请求
        // 如果API设计为接受查询参数，则这是可以的；否则，应考虑将参数放在请求体中
        Response response = RestAssured.given()
                .body(formData)
                .cookies(cookies)
                .baseUri("http://10.1.10.141:9031")
                .post("/pingyin.do?method=getMap&csrftoken="); // 假设这里有一个有效的CSRF Token或它是不必要的

        int statusCode = response.getStatusCode();
        String body = response.getBody().asString();

        System.out.println("Status Code: " + statusCode);
        System.out.println("Response Body: " + body);

        return statusCode;


    }

}


